<?php

$css = array('jquery-ui.css', 'form.css');
$javascript = array('add_common.js', 'add_pago.js');

flep_structure($structure, 'entrada');

function include_page($structure){
  $user = &$_SESSION['user'];
  $edit = false;
  if(isset($_POST['id'])){
    $structure['where'][0] = sprintf("`%s`.`id`='%s'", $structure['table'], flep_decode($_POST['id']));
    $edit = flep_search_all($structure);
  }
?><br>
  <b><img src="img/add_entrada.png">&nbsp;<?php echo (!$edit?'Nueva ':'')?>Entrada</b>
  <br><br><br>
  <form action="store.php?type=entrada" method="POST" id="form_entrada" name="form_entrada">
    <input type="hidden" value="<?php echo ($edit?flep_encode($structure['data'][0]['id']):'')?>" id="id" name="id">
        <table>
           <tr>
                <td><label>Entrada #</label></td>
                <td><input type="text" autofocus name="entrada" style="width: 50px" value="<?php echo ($edit?$structure['data'][0]['entrada']:'')?>" required placeholder="#"></td>
            </tr>
            <tr>
                <td><label>Fecha de Inicio:</label></td>
                <td><input type="text" name="fecha_inicio" id="fecha_inicio" style="width: 200px" value="<?php echo ($edit?$structure['data'][0]['fecha_inicio']:'')?>" required placeholder="Formato: YYYY-MM-DD" ></td>
            </tr>
            <tr>
                <td><label>Fecha de Cierre:</label></td>
                <td><input type="text" name="fecha_cierre" id="fecha_cierre" style="width: 200px" value="<?php echo ($edit?$structure['data'][0]['fecha_cierre']:'')?>" required placeholder="Formato: YYYY-MM-DD" ></td>
            </tr>
            <tr>
                <td><label>Programa:</label></td>
                <td><select name="programa_id" id="programa_id" required ><?php
                    flep_structure($programas, 'programa');
                    $options = "";
                    if (flep_search_all($programas))
                        foreach ($programas['data'] as $programa) {
                            printf('<option value="%s" %s>%s</option>', flep_encode($programa['id']), ($edit && $structure['data'][0]['programa_id'] === $programa['id'] ? 'selected' : ''), $programa['programa']);
                }
                ?></select></td>
            <tr>
            <tr>
                <td><label onclick="flep_show_comment('textarea_entrada');" title="Click para mostrar/ocultar">Descripcion:</label></td>
                <td><textarea style="display: none;" form="form_entrada" name="descripcion" id="textarea_entrada"><?php echo ($edit?$structure['data'][0]['descripcion']:'')?></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Guardar" style="margin-right: 25px;"><input type="reset" value="Restablecer"></td>
            </tr>
        </table>
    </form>
<?php
}
?>
